

export function MP(ak) {

    return new Promise(function (resolve, reject) {
        window.onload = function () {

            resolve(BMapGL);
        }

        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = `//api.map.baidu.com/api?type=webgl&v=1.0&ak= ${ak}&callback=init`;
        script.onerror = reject;
        document.body.appendChild(script);
    })
}

/***
 * 腾讯坐标转百度坐标
 * https://blog.csdn.net/bivesou/article/details/102552671
 * @param lat
 * @param lng
 * @returns {{lng: number, lat: number}}
 */
export function changeLatLng(lat, lng) {
    var x_pi = (3.14159265358979324 * 3000.0) / 180.0;
    var x = parseFloat(lng);
    var y = parseFloat(lat);
    var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
    var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
    lng = z * Math.cos(theta) + 0.0065;
    lat = z * Math.sin(theta) + 0.006;
    return { lng, lat };
}
